package Demo1299.Demo22;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        List<Person> run = run();
        for (Person person : run) {
            System.out.println(person);
        }
    }

    public static List<Person> run() throws Exception {
        ArrayList<Person> plist = new ArrayList<>();
        List<String> list1 = FileUtils.readLines(new File("C:\\Daymate\\src\\Demo1299\\Demo22\\data1.txt"));
        HashMap<String, String> map = new HashMap<>();
        for (String s : list1) {
            String[] split = s.split("=");
            map.put(split[0],split[1]);
        }
        List<String> list2 = FileUtils.readLines(new File("C:\\Daymate\\src\\Demo1299\\Demo22\\data2.txt"));
        for (String s : list2) {
            s = s.substring(1, s.length() - 2);
            String[] split = s.split(" ");
            String[] sp = s.split("”");
            for (Map.Entry<String, String> m : map.entrySet()) {
                if(split[0].equals(m.getKey())){
                    Class<?> aClass = Class.forName(m.getValue());
                    Object newInstance = aClass.getDeclaredConstructor(String.class, String.class, int.class).newInstance(sp[0].split("“")[1], sp[1].split("“")[1], Integer.parseInt(sp[2].split("“")[1]));
                    plist.add((Person) newInstance);
                }
            }
        }
        return plist;
    }
}
